﻿using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TestingPlatForm.MissionContrl.ViewModels;

namespace TestingPlatForm.MissionContrl.Views
{
    /// <summary>
    /// MemoView.xaml 的交互逻辑
    /// </summary>
    public partial class MemoView : UserControl
    {
        public MemoView()
        {
            InitializeComponent();
        }

        public void CombinedDialogOpenedEventHandler(object sender, DialogOpenedEventArgs eventArgs)
        {
            CombinedCalendar.SelectedDate = ((MemoViewModel)DataContext).Date;
            CombinedClock.Time = ((MemoViewModel)DataContext).Time;
            CombinedCalendarEnd.SelectedDate = ((MemoViewModel)DataContext).DateEnd;
            CombinedClockEnd.Time = ((MemoViewModel)DataContext).TimeEnd;

        }

        public void CombinedDialogClosingEventHandler(object sender, DialogClosingEventArgs eventArgs)
        {
            if (Equals(eventArgs.Parameter, "1") &&
                CombinedCalendar.SelectedDate is DateTime selectedDate)
            {
                DateTime onlyDatePart = selectedDate.Date;
                var combined = onlyDatePart.AddSeconds(CombinedClock.Time.TimeOfDay.TotalSeconds);
                ((MemoViewModel)DataContext).Time = combined;
                ((MemoViewModel)DataContext).Date = combined;
            }

        }

        public void CombinedDialogClosingEventHandler2(object sender, DialogClosingEventArgs eventArgs)
        {
            if (Equals(eventArgs.Parameter, "1") &&
                CombinedCalendarEnd.SelectedDate is DateTime selectedDate)
            {
                DateTime onlyDatePart = selectedDate.Date;
                var combined = onlyDatePart.AddSeconds(CombinedClockEnd.Time.TimeOfDay.TotalSeconds);
                ((MemoViewModel)DataContext).DateEnd = combined;
                ((MemoViewModel)DataContext).TimeEnd = combined;
            }

        }
    }
}
